package com.hrprojectback.controller.ShuXingSheZhi.DeptShuXing;

import com.hrprojectback.dto.*;
import com.hrprojectback.enums.StatusEnum;
import com.hrprojectback.service.ShuXingSheZhiService.DeptShuXingService.DeptShuXingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
public class DeptTypeController {
    @Autowired
    private DeptShuXingService deptShuXingService;

    @GetMapping("/deptType")
    public ResponseDTO getDeptType(DeptTypeInfo deptTypeInfo) {
        //获取部门类型的总数量
        Integer deptTypeCounts = deptShuXingService.getDeptTypeCounts(deptTypeInfo.getTypeCode(), deptTypeInfo.getTypeName());
        //开始页
        int pageStart = (deptTypeInfo.getPageNum() - 1) * deptTypeInfo.getPageSize();
        List<DeptType> deptTypes = deptShuXingService.getDeptType(deptTypeInfo.getTypeCode(), deptTypeInfo.getTypeName(), pageStart, deptTypeInfo.getPageSize());
        if (deptTypes.size() == 0) {
            return Response.error2(StatusEnum.DEPT_TYPE_NOT_EXIST.getCode(), StatusEnum.DEPT_TYPE_NOT_EXIST.getMessage(), deptTypes);
        }
        HashMap<String, Object> res = new HashMap<>();
        res.put("deptTypeCounts", deptTypeCounts);
        res.put("data", deptTypes);
        return Response.success(res);
    }
    /**
     * 新增部门类型接口
     *
     * @param deptType
     * @return
     */
    @PostMapping("/addDeptType")
    public ResponseDTO addDeptType(@RequestBody DeptType deptType) {
        int i =deptShuXingService.addDeptType(deptType);
        if (i > 0) {
            return Response.success(deptType);
        }
        return Response.error();
    }

    /**
     *
     */

}
